<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%><%@include file="/web/base/header.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<fieldset class="layui-elem-field">
		<legend>病人信息</legend>
		<div class="layui-field-box">
			<form class="layui-form">
				
				
				<div class="layui-form-item">
					<label class="layui-form-label">病人姓名</label>
					<div class="layui-inline">
						<input type="text" name="patientname" placeholder="请输入病人姓名"
							autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">病人性别</label>
					<div class="layui-inline">
					<input type="text" name="patientsex" placeholder="请输入病人性别"
						autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
							<label class="layui-form-label">主治医生</label>
							<div class="layui-inline">
								<select name="doctorname" lay-filter="doctor" id="doctor">
									<option value="" selected>请选择主治医生</option>
      							</select>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">病房地址</label>
							<div class="layui-inline">
								<select name="roomaddress" lay-filter="room" id="room">
									<option value="" selected>请选择病房地址</option>
      							</select>
							</div>
						</div>
				&nbsp;&nbsp; <input id="sele" type="submit" class="layui-btn" lay-submit
					lay-filter="select" value="查找" /> 
				
				<input name="action" type="hidden" value="page"/>
				<input name="curr" type="hidden" value="1"/>
				<input name="limit" type="hidden" value="10"/>
			</form>

		</div>
		<table class="layui-table">

			<thead>
				<tr>
					<th>序号</th>
					<th>病人姓名</th>
					<th>病人性别</th>
					<th>主治医生姓名</th>
					<th>所住病房</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody id="patienttbody"></tbody>
		</table>
		
		<div id="page"></div>


	</fieldset >
	
	<script type="text/javascript" >
	select();
	formon('submit(select)',base.app+'/PatientServlet','json',
			function(data2){
			var tar=JSON.stringify(data2);
			resp = JSON.parse(tar);
			setpage("page",resp["count"],$("input[name='curr']").val(),$("input[name='limit']").val(),
					function(obj,first){
				$("input[name='curr']").val(obj.curr);
				$("input[name='limit']").val(obj.limit);
				if(!first){
					f5("input[value='查找']");
				}
			});
            var list = resp["list"];
            var roomlist=resp["roomlist"];
            var doctorlist = resp["doctorlist"];
			var html="";
				$.each(list,function(i,dom){
					var name=dom.patientName?dom.patientName:'';
					var sex=dom.patientSex?dom.patientSex:'';
					
					var roomaddress;
					var roomid=dom.roomId?dom.roomId:'';
					$.each(roomlist,function(j,dom1){
						var id=dom1.roomId?dom1.roomId:'';
						if(id==roomid){
							roomaddress=dom1.roomAddress?dom1.roomAddress:'';
							
						}
					})
					
					var doctorname;
					var doctorid=dom.doctorId?dom.doctorId:'';
					$.each(doctorlist,function(j,dom1){
						var id=dom1.doctorId?dom1.doctorId:'';
						if(id==doctorid){
							doctorname=dom1.doctorName?dom1.doctorName:'';
							
						}
					})
					
					html+="<tr>"+
						"<td>"+ (i+1) +"</td>"+
						"<td>"+name+"</td>"+
						"<td>"+sex+"</td>"+
						"<td>"+doctorname+"</td>"+
						"<td>"+roomaddress+"</td>"+
						"<td>"+
						"<a href='javascript:del("+name+");' class='layui-btn'>删除</a>"+
						"<a href='javascript:tanupd("+name+");' class='layui-btn'>修改</a>"+
						"</td></tr>";
				})
				$("#patienttbody").html(html);
				
		})
		
		f5("input[value='查找']");
	
	function del(name){
		if(confirm("确定删除")){
			var data={delname:name,action:"del"};
			ajax1(data,base.app+'/PatientServlet',"text",function(data){
				if("1"==data){
					alert("删除成功");
				}else{
					alert("删除失败");
				}
			})
			f5("input[value='查找']");
		}
	}
	
	function tanupd(name){
		layer.open({
			type: 1,
			area: ['400px', '400px'],
			content: $("#updhtml").html(),
			title: "修改",
			success: function(index) {
				var data1={updname:name,action:"selectmodel"};
				ajax1(data1,base.app+'/PatientServlet','json',
						function(data3){
							var tar=JSON.stringify(data3);
							resp = JSON.parse(tar);
		            		var model = resp["selectmodel"];
							var indata={
									patientname:model.patientName,
									patientsex:model.patientSex
							};
							form.val("updform", indata);
							
				});
				
				form.render();
				formon('submit(upd)',base.app+'/PatientServlet','text',
					function(data2){
						if("1"==data2){
							alert("修改成功");
							f5("input[value='查找']");
							closeThis();
						}
						if("2"==data2){
							alert("请输入数据");
						}
						if("0"==data2){
							alert("修改失败");
						}
					})
					
			}
		});
	}
	</script>
	
	<script type="text/html" id="updhtml">
		<form class="layui-form" lay-filter="updform">
				
				
				
				<div class="layui-form-item">
					<label class="layui-form-label">病人性别</label>
					<div class="layui-inline">
					<input type="text" name="patientsex" placeholder="请输入病人性别"
						autocomplete="off" class="layui-input">
					</div>
				</div>
						
						<div class="layui-form-item">
							<div class="layui-input-block">
								<button class="layui-btn" lay-submit lay-filter="upd">提交</button>
								<button type="reset" class="layui-btn layui-btn-primary">重置</button>
							</div>
						</div>
						<input type="hidden" name="patientname"/>
						<input type="hidden" name="action" value="upd"/>
					</form>

	</script>
		
</body>
</html>